package com.six.flowerShopper.mapper

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper
import com.baomidou.mybatisplus.core.mapper.BaseMapper
import com.six.flowerShopper.entity.PurchaseHistory
import org.apache.commons.lang.StringUtils
import org.apache.ibatis.annotations.Mapper
import org.apache.ibatis.annotations.Select


/*-*- coding:utf-8 -*-
 * @Author  : debi
 * @Time    : 10/22/22
 * @Software: IntelliJ IDEA
 */
@Mapper
interface PurchaseHistoryMapper : BaseMapper<PurchaseHistory> {
    @Select("SELECT * FROM FlowerManage.purchaseHistory  ")
    fun findAll(): MutableList<PurchaseHistory>

}


fun PurchaseHistory.Companion.nameNotEmptyLike(userName: String): QueryWrapper<PurchaseHistory> =
    QueryWrapper<PurchaseHistory>().apply {
        this.like(StringUtils.isNotEmpty(userName), "name", userName)
    }

fun PurchaseHistory.Companion.queryByUserId(userId: Int): QueryWrapper<PurchaseHistory> =
    QueryWrapper<PurchaseHistory>().apply {
        this.eq(userId > 0, "userId", userId)
    }

fun PurchaseHistory.Companion.updateWrapper(ph: PurchaseHistory): UpdateWrapper<PurchaseHistory> =
    UpdateWrapper<PurchaseHistory>().apply {
        this.eq(ph.userId > 0, "userId", ph.userId)
    }
fun PurchaseHistory.Companion.delWrapper(ph: PurchaseHistory): UpdateWrapper<PurchaseHistory> =
    UpdateWrapper<PurchaseHistory>().apply {
        this.eq("id", ph.id)
        this.eq("userId", ph.userId)
        this.eq("flowerId", ph.flowerId)
    }

